import axios from 'axios'

const API_BASE_URL = 'http://localhost:8080/api'

const api = axios.create({
    baseURL: API_BASE_URL,
    timeout: 30000,
    headers: {
        'Content-Type': 'application/json'
    }
})

export const chatAPI = {
    sendMessage: (role, message, conversationId = null) => {
        const payload = { role, message }
        if (conversationId) {
            payload.conversationId = conversationId
        }
        return api.post('/chat', payload)
    },

    getConversations: () => {
        return api.get('/conversations')
    },

    getConversationMessages: (conversationId) => {
        return api.get(`/conversations/${conversationId}/messages`)
    },

    healthCheck: () => {
        return api.get('/health')
    }
}

export default api